<template>
  <div>
    <h2 align="center">投资项目添加页面</h2>
    <table class="table table-bordered">
      <tr>
        <td>投资名称</td>
        <td>
          <input type="text" v-model="addData.T_Name" >
        </td>
      </tr>

      <tr>
        <td>投资总金额</td>
        <td>
          <input type="text" v-model="addData.T_Total" >
        </td>
      </tr>

      <tr>
        <td></td>
        <td>
          <input type="button" value="添加" @click="addInfo" >
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router'
import axios from 'axios'

let router = useRouter()

let route = useRoute()

//数据
let data = reactive({
  addData:{
    T_Name:'',
    T_Total:''
  }
})
//解构
let {addData} = toRefs(data)

//添加方法
const addInfo =()=>{
  //非空判断
  if(addData.value.T_Name==""){
    return alert('投资名称不能为空')
  } 
  if(addData.value.T_Total==""){
    return alert('投资总金额不能为空')
  }
  //判断是否为数字
  if(isNaN(addData.value.T_Total)){
    return alert('投资总金额必须为数字')
  }  
  if(addData.value.T_Total<100000){
    return alert('投资总金额必须大于100000')
  }

  axios({
    url:'/api/Invest/PostAddInfo',
    method:'post',
    data:addData.value
  }).then(res=>{
    if(res.data.data==-1){
      return alert('该投资名称已存在')
    }else if(res.data.data >0){
      alert('添加成功')
      router.push({
        path:'/showInvest'
      })
    }else{
      alert('添加失败')
    }
  })
}

</script>

<style scoped>

</style>